<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.global.js"></script>
    <style>

        #counter {
            width: 50%;
            height: 500px;
            margin: 0 auto;
            /* display: flex; */
            /* justify-content: center;
            align-items: center; */
        }
    </style>
</head>
<body>
    <div id="counter">
        <input type="text" v-focus v-model="taskInput"> <input type="button" value="添加" @click="add()"><br>
        <br>
        <h2>正在执行的任务</h2>
        
        <div class="doing" v-for="(item, index) in dolist" :key="item.time">
            <div class="wrapdoing" @click="finsh(index)" v-show="!item.isFinsh">{{index + 1}}.{{item.task}} -----{{item.time}}</div>
        </div>  
        <hr>
        <h2>已完成的任务</h2>
        <div class="done" v-for="(item, index) in dolist" :key="item.time">
            <div class="wrapdone" v-show="item.isFinsh" @click="finsh(index)">{{index + 1}}.{{item.task}} -----{{item.time}}</div>
        </div>
    </div>
</body>
<script>
let Counter ={
    data() {
        return {
            dolist: [{task: "例任务1", time: "00:00:00", isFinsh: false}],
            index: null,
            taskInput: '',
        }
    },
    methods: {
        finsh(index) {
            if (this.dolist[index].isFinsh == true) {
                this.dolist[index].isFinsh = false
            }else {
                this.dolist[index].isFinsh = true
            }
            console.log(index)
            
        },
        add() {
            let date = new Date()
            console.log(date)
            let year = date.getFullYear()
            let month = date.getMonth() + 1
            let day = date.getDate()
            let hours = date.getHours()
            let minutes = date.getMinutes()
            let seconds = date.getSeconds()

            if (this.taskInput != '') {
                let newTask = {
                    task: this.taskInput,
                    time: hours + ":" + minutes + ":" + seconds,
                    isFinsh: false
                }
                this.dolist.push(newTask)
                this.taskInput = ''
            }
            
        }
    },
}

const app = Vue.createApp(Counter)
app.directive('focus', {
    mounted(el, delivered) {
      // 聚焦元素
      console.log(delivered)
      el.value = delivered.value
      console.log(el.value)
      el.focus()
    }
})
app.directive('add', {
    update(el) {
        console.log(el)
    },
})
app.mount("#counter")



</script>
</html>